package com.chixing.day10_hashcode_exception.homework;

import java.util.Arrays;
import java.util.Objects;

public class Company {
    private int comId;
    private String comName ;
    private String comType;
    private String Label;

    private Position []position = new Position[5]; //存储公司数组
    private Position []comPosition = new Position[5];  //存储计算机类招聘岗位

    private int coont = 0;//计数器
    //发布职位方法
    public void posting(int id,String name,float min,float max,String city,String education,Company company){
        if (coont == 5) {System.out.println("职位已满"); return;}
        Position temp = new Position(id,name,min,max,city,education,company);
        for (int i = 0; i < coont; i++) {
            if (temp.equals(position[i])){
                System.out.println("已存在该职位,请勿重复添加");
                return;
            }
        }

        position[coont++] = temp;
    }
    //查询出"计算机"类的公司 招聘的岗位，存储到数组中
    public void selectEducation(String Education){
        int temp = 0;
        for (int j = 0; j < coont; j++) {
            if (position[j].getCompany().getLabel().contains(Education)) {
                comPosition[temp++] = position[j] ;
            }
        }
        for (int i = 0; i <temp; i++) {
            System.out.println(comPosition[i].toString());
        }
    }


    //显示已发布的职位
    public void show(){
        System.out.println("已发布的职位");
        for (int i = 0; i < coont; i++) {
            System.out.println(position[i].toString());
        }
    }
    //统计地区的岗位发布数量
    public void selectCitynum(Company company){
        int com1 = 0;
        String cityTemp ="";
        for (int i = 0; i < coont; i++) {
            if (position[i].getCompany().getComName() == company.getComName()){
                cityTemp += position[i].getPotCity() + " ";
                com1++;
            }
        }
        System.out.println(company.comName+"：");
        String []cityT = cityTemp.split(" ");
        for (int t = 0; t < cityT.length; t++) {
            int connt = 0;
            int num = 0;
            if (cityT.length==1) {System.out.println("该公司没有发布岗位");return;}
            if (!cityTemp.substring(0, t+1).contains(cityT[t])) {
                while (cityTemp.indexOf(cityT[t], connt) != -1) {
                    connt = cityTemp.indexOf(cityT[t], connt) + 1;
                    num++;
                }
                System.out.println(cityT[t] + "的发布数量:" + num);
            }
        }
    }
    public Company(int comId, String comName, String comType, String label) {
        this.comId = comId;
        this.comName = comName;
        this.comType = comType;
        Label = label;
    }

    public Company() {

    }


    @Override
    public int hashCode() {
        int result = Objects.hash(comId, comName, comType, Label, coont);
        result = 31 * result + Arrays.hashCode(position);
        return result;
    }

    public int getComId() {
        return comId;
    }

    public void setComId(int comId) {
        this.comId = comId;
    }

    public String getComName() {
        return comName;
    }

    public void setComName(String comName) {
        this.comName = comName;
    }

    public String getComType() {
        return comType;
    }

    public void setComType(String comType) {
        this.comType = comType;
    }

    public String getLabel() {
        return Label;
    }

    public void setLabel(String label) {
        Label = label;
    }

}
